﻿using System;

namespace Behaviours.Helper
{
    public static class TimeHelper
    {
        private static int _timeZone;
        private static DateTime dt1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
        private static DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
        public static int TimeZone
        {
            get
            {
                return _timeZone;
            }
            set
            {
                _timeZone = value;
                dt = dt1970.AddHours(TimeZone);
            }
        }
        

        public static long FrameTime;

        public static void Update()
        {
            FrameTime = TimeStamp();
        }
        
        /// <summary> 
        /// 根据时间戳获取时间 
        /// </summary>  
        public static DateTime ToDateTime(long timeStamp)
        {
            return dt.AddTicks(timeStamp * 10000);
        }
        
        // 线程安全
        public static long TimeStamp()
        {
            return (DateTime.Now.Ticks - dt1970.Ticks) / 10000;
        }
    }
}